
import java.io.FileInputStream
import com.talkingdata.hadoop.bean.XmlConfig
import com.talkingdata.hadoop.service.HadoopService
import com.talkingdata.hadoop.util.QuillCon
import org.apache.log4j.Logger

import scala.collection.mutable.ListBuffer
import scala.xml.XML

object RunReport {
	def main(args: Array[String]): Unit = {
		for (xc <- getConfigure()) {
			val qc = new QuillCon
			val hdfs = new HadoopService(xc)
			hdfs.getRMState()
			hdfs.getCapacityScheduler()
			/*hdfs.getYarnClusterStatus()
			hdfs.getNamenodeState()
			hdfs.getDfsClusterStatus()
			// 数据库持久化
			qc.batchInsertNameNode(hdfs.getNamenodeState().toList)
			qc.insertDfsClusterState(hdfs.getDfsClusterStatus())
			qc.batchInsertRM(hdfs.getRMState().toList)
			qc.insertYarnClusterState(hdfs.getYarnClusterStatus())*/
		}
	}

	def getConfigure(): ListBuffer[XmlConfig] = {
		val configure_dir = "conf/"
		@transient lazy val log = Logger.getLogger(this.getClass)
		val xmlInfoListBuffer: ListBuffer[XmlConfig] = ListBuffer()
		val conf = new FileInputStream(configure_dir + "configure.xml")
		val xmlConfig = XML.load(conf)
		val clusterList = (xmlConfig \ "cluster")
		for (cluster <- clusterList) {
			val clusterId = (cluster \ "serviceId").text
			val clusterConfFileDir = configure_dir + clusterId + "/"
			val kerberos = (cluster \ "kerberos").text
			val kerberos_user = (cluster \ "kerberos_user").text
			val kerberos_keytab = configure_dir + clusterId + "/" + (cluster \ "kerberos_keytab").text
			val scheduler = (cluster \ "scheduler").text
			val version = (cluster \ "version").text
			val info = XmlConfig(1, clusterId, clusterConfFileDir, kerberos.toBoolean, kerberos_user, kerberos_keytab, scheduler, version)
			val configInfo = ("clusterId : " + clusterId +
					"\tclusterConfFileDir : " + clusterConfFileDir +
					"\tkerberos : " + kerberos +
					"\tkerberos_user : " + kerberos_user +
					"\tkerberos_keytab : " + kerberos_keytab +
					"\tscheduler : " + scheduler +
					"\tversion : " + version)
			// 添加到最后
			xmlInfoListBuffer.append(info)
			log.info(configInfo)
		}
		xmlInfoListBuffer
	}
}
